﻿using System;
using System.Linq;

using Microsoft.Phone.Controls;

namespace NavigationCoercion.Actions
{
    internal class RemoveTillPageAction : RemoveActionBase
    {
        private readonly string _pageType;

        internal RemoveTillPageAction(Type pageType)
        {
            this._pageType = pageType.GetPossibleXamlPagePath();
        }

        internal override void PerformRemoval(PhoneApplicationFrame frame)
        {
            while (frame.BackStack.First().Source.ToString() != this._pageType)
            {
                frame.RemoveBackEntry();
            }
        }
    }
}